//
//  AllQuestViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/6.
//

#import "AllQuestViewController.h"
#import "joinQuestViewController.h"
#import "myQuestViewController.h"
#import "joinResultViewController.h"
#import "joinScreenModel.h"

@interface AllQuestViewController ()

@property (nonatomic ,strong)  UIView * btnline;
@property (nonatomic ,strong)  UIButton * myBtn;
@property (nonatomic ,strong)  UIButton * jjBtn;
@property (nonatomic ,strong)  myQuestViewController * myvc;
@property (nonatomic ,strong)  joinQuestViewController * jjvc;
@property (nonatomic ,strong)  UIButton * jjSSBtn;



@end

@implementation AllQuestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.shutDownBack = YES;
    
    UIView * topview = [UIView new];
    topview.backgroundColor = KcolorHex(@"#0967FF");
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX +10);
    }];
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf popViewController];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44 + 10);
        make.left.bottom.offset(0);
        make.width.offset(kwt(170));
    }];
    
    UIImageView * leftimg = kimageView(@"white_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UIView * btnview = [UIView new];
    [DTKTool YJ:8 andView:btnview];
    btnview.backgroundColor = KcolorHex(@"#3284FB");
    [topview addSubview:btnview];
    [btnview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.equalTo(leftimg);
        make.width.offset(kwt(250));
        make.height.offset(38);
    }];
    
    UIView * btnline = [UIView new];
    self.btnline = btnline;
    [DTKTool YJ:8 andView:btnline];
    btnline.backgroundColor = UIColor.whiteColor;
    [btnview addSubview:btnline];
    
    UIButton * myBtn = [UIButton buttonWithType:0];
    myBtn.addTarget(self,@selector(myBtnClick));
    myBtn.addNormalColor(UIColor.whiteColor).addNormalText(@"我的任务").addFont(kFont(19));
    [myBtn setTitleColor:KcolorHex(@"#0967FF") forState:UIControlStateSelected];
    self.myBtn = myBtn;
    [btnview addSubview:myBtn];
    [myBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.offset(0);
        
    }];
    UIButton * jjBtn = [UIButton buttonWithType:0];
    jjBtn.addTarget(self,@selector(jjBtnClikc));
    jjBtn.addNormalColor(UIColor.whiteColor).addNormalText(@"交接任务").addFont(kFont(19));
    [jjBtn setTitleColor:KcolorHex(@"#0967FF") forState:UIControlStateSelected];
    self.jjBtn = jjBtn;
    [btnview addSubview:jjBtn];
    [jjBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.offset(0);
        make.left.equalTo(myBtn.mas_right);
        make.width.equalTo(myBtn);
    }];
    
    UIButton * jjSSBtn = [UIButton buttonWithType:0];
    self.jjSSBtn = jjSSBtn;
    jjSSBtn.addimg([UIImage imageNamed:@"seach"]).addTarget(self,@selector(jjssBtnclick));
    [topview addSubview:jjSSBtn];
    [jjSSBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.centerY.equalTo(btnview);
        make.width.height.offset(kwt(30));
    }];
    
    myQuestViewController * myvc = [myQuestViewController new];
    self.myvc = myvc;
    if(self.isDB){
        myvc.state = 1;
    }
    myvc.pondId = self.pondId;
    myvc.pondName = self.pondName;
    myvc.xspondName = self.xspondName;
    [self.view addSubview:myvc.view];
    [self addChildViewController:myvc];
    [myvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
    }];
    joinQuestViewController * jjvc = [joinQuestViewController new];
    self.jjvc = jjvc;
    [self.view addSubview:jjvc.view];
    [self addChildViewController:jjvc];
    [jjvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
    }];
    if(self.isJJ){
        [self jjBtnClikc];
    } else {
        [self myBtnClick];
    }
}
- (void)jjssBtnclick{
    joinResultViewController * vc = [joinResultViewController new];
    vc.model = [joinScreenModel yy_modelWithJSON:[self.jjvc.model yy_modelToJSONString]];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)myBtnClick{
    if(self.myBtn.selected == NO){
        self.myBtn.selected = YES;
        self.myBtn.addFont(kCFont(19));
        self.jjBtn.selected = NO;
        self.jjBtn.addFont(kFont(19));
        [UIView animateWithDuration:0.25 animations:^{
            self.btnline.frame = CGRectMake(0, 0, kwt(125), 38);
        }];
        self.myvc.view.hidden = NO;
        self.jjvc.view.hidden = YES;
        self.jjSSBtn.hidden = YES;
    }
}

- (void)jjBtnClikc{
    if(self.jjBtn.selected == NO){
        self.jjBtn.selected = YES;
        self.jjBtn.addFont(kCFont(19));
        self.myBtn.selected = NO;
        self.myBtn.addFont(kFont(19));
        [UIView animateWithDuration:0.25 animations:^{
            self.btnline.frame = CGRectMake(kwt(125), 0, kwt(125), 38);
        }];
        self.myvc.view.hidden = YES;
        self.jjvc.view.hidden = NO;
        self.jjSSBtn.hidden = NO;
    }
}

@end
